$(function(){
	// 获取参数
	var mainGuid = cmedit.global.getParameterFromUrl("mainGuid");
	var tenantId = cmedit.global.getParameterFromUrl("tenantId");
	
	$.ajax({
		type: "post",
		async: true,
		dataType: "json",
		url: cmedit.global.cmsPath+"CmsController/getWebManuscriptByGuid",
		data: {
			"mainGuid" : mainGuid,
			"tenantId" : tenantId
		},
		success: function (data) {
			if (data.status) {
				// 渲染稿件信息
				var manuscript = data.data;
				$("#title").html(manuscript.mainHeader);
				$("#username").html(manuscript.mainCreateUserName);
				$("#createtime").html(manuscript.mainCreateTime);
				$("#webContent").html(manuscript.cmsH5Content);
				// 对稿件中的图片进行大小格式化
				debugger;
				var screenWidth = $(window).width();
				var screenHeight = $(window).height();
				$('#webContent img').load(function(){
					setWidthHeight(this,screenWidth-30);
				});
				$('#webContent img').error(function(){
					getFail(this);
				});
				if(screenWidth<500){
					$('html').css('width',screenWidth);
					$('body').css('width',screenWidth);
					$('#contentDiv').css('width',(screenWidth*0.92)+'px');
					$('#contentDiv').css('height',screenHeight+'px');
					$('.h1Class').css('font-size','23px');
					$('#webContent').css('font-size','16px');
					$('#webContent').css('word-break','break-word');
					$('#webContent').addClass("vid-wrapperOther");
				}
			} else {
				console.log(data);
			}
		}
	});
	

		function setWidthHeight(ImgD, screenWidth) {// 参数(图片,允许的宽度,允许的高度)
//			var iwidth = screenWidth;
			var iwidth = 970;
			var iheight = 2000;
			var src = $(ImgD).attr("src");
			var imgwidth = $(ImgD).outerWidth();
			var imgheight = $(ImgD).outerHeight();
			if(imgwidth>0 && imgheight>0){
     		   if(imgwidth/imgheight>= iwidth/iheight){
     			   if(imgwidth>iwidth){
     				   $(ImgD).attr("width", iwidth+"px");
     				   $(ImgD).attr("height",((imgheight*iwidth)/imgwidth)+"px");
     			   }else{
     				   $(ImgD).attr("width", imgwidth+"px");
     				   $(ImgD).attr("height", imgheight+"px");
     			   }
     		   }else{
     			   if(imgheight>iheight){
     				   $(ImgD).attr("width", ((imgwidth*iheight)/imgheight)+"px");
     				   $(ImgD).attr("height", iheight+"px");
     			   }else{
     				   $(ImgD).attr("width", imgwidth+"px");
     				   $(ImgD).attr("height", imgheight+"px");
     			   }
     		   }
     	   }
		}
		

	/**
	 * 图片加载失败方法
	 * 
	 * @param imgObj
	 */
	function getFail(imgObj, manuscripttype) {
		var screenWidth = $(window).width();
		$(imgObj).attr('alt', '');
		if (screenWidth < 500) {
			$(imgObj).css('width', screenWidth * 0.92);
			$(imgObj).css('height', screenWidth * 0.92);
		} else {
			if (manuscripttype == 1) {
				$(imgObj).css('width', '100%');
				$(imgObj).css('height', $(imgObj).outerWidth());
			} else {
				$(imgObj).css('width', '440px');
				$(imgObj).css('height', '440px');
			}
		}
	}
});